home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / c / EGCSWOSAlib.lha / src.lha / TimeDelay.c < prev    next >
C/C++ Source or Header  |  1999-01-04  |  2KB  |  54 lines

  1. /*
  2. ** amiga.lib for vbcc-PowerOpen/WarpOS
  3. **
  4. ** TimeDelay()
  5. **
  6. ** V0.2 19-Apr-98 phx
  7. **      replaced <clib/powerpc/powerpc_protos.h> by <clib/powerpc_protos.h>
  8. ** V0.1 15-Mar-98 phx
  9. **      created
  10. */
  11.  
  12. #include <exec/memory.h>
  13. #include <devices/timer.h>
  14. #include <proto/exec.h>
  15. #include <powerpc/powerpc_protos.h>
  16.  
  17. #define NEWLIST(l) ((l)->lh_Head = (struct Node *)&(l)->lh_Tail, \
  18.                     (l)->lh_TailPred = (struct Node *)&(l)->lh_Head)
  19.  
  20. LONG TimeDelay(long unit, unsigned long secs, unsigned long microsecs)
  21. {
  22.   struct PortIO {
  23.     struct timerequest treq;
  24.     struct MsgPort port;
  25.   } *portio;
  26.   long ret=-1;
  27.  
  28.   if ((portio = (struct PortIO *)AllocVecPPC(sizeof(struct PortIO),
  29.                                              MEMF_CLEAR|MEMF_PUBLIC,0)))
  30.   {
  31.     portio->port.mp_Node.ln_Type=NT_MSGPORT;
  32.     if ((BYTE)(portio->port.mp_SigBit=AllocSignal(-1))>=0)
  33.     {
  34.       portio->port.mp_SigTask=FindTask(NULL);
  35.       NEWLIST(&portio->port.mp_MsgList);
  36.  
  37.       portio->treq.tr_node.io_Message.mn_Node.ln_Type=NT_MESSAGE;
  38.       portio->treq.tr_node.io_Message.mn_ReplyPort=&portio->port;
  39.       if (!(OpenDevice(TIMERNAME,unit,&portio->treq.tr_node,0)))
  40.       {
  41.         portio->treq.tr_node.io_Command=TR_ADDREQUEST;
  42.         portio->treq.tr_time.tv_secs=secs;
  43.         portio->treq.tr_time.tv_micro=microsecs;
  44.         if (!DoIO(&portio->treq.tr_node))
  45.           ret=0;
  46.         CloseDevice(&portio->treq.tr_node);
  47.       }
  48.       FreeSignal(portio->port.mp_SigBit);
  49.     }
  50.     FreeVecPPC(portio);
  51.   }
  52.   return ret;
  53. }
  54.